//
// Created by Tan Ke on 2024/1/20.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

struct Node {
    int val;
    struct Node* next;
};

int singleNumber(int* nums, int numsSize)
{
    struct Node* list = (struct Node*)malloc(sizeof(struct Node));
    list->next = NULL;

    for (int i = 0; i < numsSize; i ++) {
        struct Node* tmp = list->next;
        struct Node* prev = list;

        while (tmp != NULL) {
            if (tmp->val == nums[i]) {
                break;
            }
            prev = tmp;
            tmp = prev->next;
        }

        if (tmp == NULL) {
            struct Node* node = (struct Node*)malloc(sizeof(struct Node));
            node->val = nums[i];
            node->next = NULL;
            prev->next = node;
        } else {
            prev->next = tmp->next;
            free(tmp);
        }
    }

    return list->next->val;
}


int main(void)
{
    int nums1[5] = {4, 1, 2, 1, 2};
    printf("%d\n", singleNumber(nums1, 5));

    return 0;
}